/*
 * 微信公众平台(JAVA) SDK
 *
 * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
 *
 * http://www.weixin4j.org/sdk/
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.mc.adapter.wechat.mpAPI.message;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.mc.adapter.wechat.mpAPI.message.event.ClickEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.EventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.LocationEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.LocationSelectEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.PicPhotoOrAlbumEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.PicSysPhotoEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.PicWeixinEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.QrsceneScanEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.QrsceneSubscribeEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.ScanCodePushEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.ScanCodeWaitMsgEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.SubscribeEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.UnSubscribeEventMessage;
import com.mc.adapter.wechat.mpAPI.message.event.ViewEventMessage;
import com.mc.adapter.wechat.mpAPI.message.normal.ImageInputMessage;
import com.mc.adapter.wechat.mpAPI.message.normal.LinkInputMessage;
import com.mc.adapter.wechat.mpAPI.message.normal.LocationInputMessage;
import com.mc.adapter.wechat.mpAPI.message.normal.NormalMessage;
import com.mc.adapter.wechat.mpAPI.message.normal.ShortVideoInputMessage;
import com.mc.adapter.wechat.mpAPI.message.normal.TextInputMessage;
import com.mc.adapter.wechat.mpAPI.message.normal.VideoInputMessage;
import com.mc.adapter.wechat.mpAPI.message.normal.VoiceInputMessage;

/**
 * POST的XML数据包转换为消息接受对象
 *
 * <p>
 * 由于POST的是XML数据包，所以不确定为哪种接受消息，<br/>
 * 所以直接将所有字段都进行转换，最后根据<tt>MsgType</tt>字段来判断取何种数据
 * </p>
 *
 * @author weixin4j<weixin4j@ansitech.com>
 */
@XmlRootElement(name = "xml")
public class InputMessage extends NormalMessage {

	private String				MsgType	= "text";
	// 文本消息
	private String				Content;
	// 图片消息
	private String				PicUrl;
	// 位置消息
	private String				Location_X;
	private String				Location_Y;
	private Long				Scale;
	private String				Label;
	// 链接消息
	private String				Title;
	private String				Description;
	private String				Url;
	// 语音信息 视频消息
	private String				MediaId;
	private String				Format;
	private String				Recognition;
	// 视频消息 视频消息缩略图的媒体id，可以调用多媒体文件下载接口拉取数据。
	private String				ThumbMediaId;
	// 事件
	private String				Event;
	private String				EventKey;
	private String				Ticket;
	// 上报地理位置事件
	private String				Latitude;
	private String				Longitude;
	private String				Precision;
	// 群发消息事件
	private String				MsgID;
	private String				Status;
	private int					TotalCount;
	private int					FilterCount;
	private int					SentCount;
	private int					ErrorCount;
	// 扫码推事件
	private ScanCodeInfo		ScanCodeInfo;
	// 拍照发图
	private SendPicsInfo		SendPicsInfo;
	// 发送地理位置
	private SendLocationInfo	SendLocationInfo;

	@Override
	public String getMsgType() {
		return this.MsgType;
	}

	@XmlElement(name = "MsgType")
	public void setMsgType(String msgType) {
		this.MsgType = msgType;
	}

	public String getContent() {
		return this.Content;
	}

	@XmlElement(name = "Content")
	public void setContent(String content) {
		this.Content = content;
	}

	public String getPicUrl() {
		return this.PicUrl;
	}

	@XmlElement(name = "PicUrl")
	public void setPicUrl(String picUrl) {
		this.PicUrl = picUrl;
	}

	public String getLocation_X() {
		return this.Location_X;
	}

	@XmlElement(name = "Location_X")
	public void setLocation_X(String locationX) {
		this.Location_X = locationX;
	}

	public String getLocation_Y() {
		return this.Location_Y;
	}

	@XmlElement(name = "Location_Y")
	public void setLocationY(String location_Y) {
		this.Location_Y = location_Y;
	}

	public Long getScale() {
		return this.Scale;
	}

	@XmlElement(name = "Scale")
	public void setScale(Long scale) {
		this.Scale = scale;
	}

	public String getLabel() {
		return this.Label;
	}

	@XmlElement(name = "Label")
	public void setLabel(String label) {
		this.Label = label;
	}

	public String getTitle() {
		return this.Title;
	}

	@XmlElement(name = "Title")
	public void setTitle(String title) {
		this.Title = title;
	}

	public String getDescription() {
		return this.Description;
	}

	@XmlElement(name = "Description")
	public void setDescription(String description) {
		this.Description = description;
	}

	public String getUrl() {
		return this.Url;
	}

	@XmlElement(name = "Url")
	public void setUrl(String url) {
		this.Url = url;
	}

	public String getEvent() {
		// 转成小写
		return this.Event.toLowerCase();
	}

	@XmlElement(name = "Event")
	public void setEvent(String event) {
		this.Event = event;
	}

	public String getEventKey() {
		return this.EventKey;
	}

	@XmlElement(name = "EventKey")
	public void setEventKey(String eventKey) {
		this.EventKey = eventKey;
	}

	public String getMediaId() {
		return this.MediaId;
	}

	@XmlElement(name = "MediaId")
	public void setMediaId(String mediaId) {
		this.MediaId = mediaId;
	}

	public String getThumbMediaId() {
		return this.ThumbMediaId;
	}

	@XmlElement(name = "ThumbMediaId")
	public void setThumbMediaId(String ThumbMediaId) {
		this.ThumbMediaId = ThumbMediaId;
	}

	public String getFormat() {
		return this.Format;
	}

	@XmlElement(name = "Format")
	public void setFormat(String format) {
		this.Format = format;
	}

	public String getRecognition() {
		return this.Recognition;
	}

	@XmlElement(name = "Recognition")
	public void setRecognition(String recognition) {
		this.Recognition = recognition;
	}

	public String getTicket() {
		return this.Ticket;
	}

	@XmlElement(name = "Ticket")
	public void setTicket(String ticket) {
		this.Ticket = ticket;
	}

	public String getLatitude() {
		return this.Latitude;
	}

	@XmlElement(name = "Latitude")
	public void setLatitude(String Latitude) {
		this.Latitude = Latitude;
	}

	public String getLongitude() {
		return this.Longitude;
	}

	@XmlElement(name = "Longitude")
	public void setLongitude(String Longitude) {
		this.Longitude = Longitude;
	}

	public String getPrecision() {
		return this.Precision;
	}

	@XmlElement(name = "Precision")
	public void setPrecision(String Precision) {
		this.Precision = Precision;
	}

	public String getStatus() {
		return this.Status;
	}

	@XmlElement(name = "Status")
	public void setStatus(String Status) {
		this.Status = Status;
	}

	public int getTotalCount() {
		return this.TotalCount;
	}

	@XmlElement(name = "TotalCount")
	public void setTotalCount(int TotalCount) {
		this.TotalCount = TotalCount;
	}

	public int getFilterCount() {
		return this.FilterCount;
	}

	@XmlElement(name = "FilterCount")
	public void setFilterCount(int FilterCount) {
		this.FilterCount = FilterCount;
	}

	public int getSentCount() {
		return this.SentCount;
	}

	@XmlElement(name = "SentCount")
	public void setSentCount(int SentCount) {
		this.SentCount = SentCount;
	}

	public int getErrorCount() {
		return this.ErrorCount;
	}

	@XmlElement(name = "ErrorCount")
	public void setErrorCount(int ErrorCount) {
		this.ErrorCount = ErrorCount;
	}

	public String getMsgID() {
		return this.MsgID;
	}

	@XmlElement(name = "MsgID")
	public void setMsgID(String MsgID) {
		this.MsgID = MsgID;
	}

	public ScanCodeInfo getScanCodeInfo() {
		return this.ScanCodeInfo;
	}

	@XmlElement(name = "ScanCodeInfo")
	public void setScanCodeInfo(ScanCodeInfo ScanCodeInfo) {
		this.ScanCodeInfo = ScanCodeInfo;
	}

	public SendLocationInfo getSendLocationInfo() {
		return this.SendLocationInfo;
	}

	@XmlElement(name = "SendLocationInfo")
	public void setSendLocationInfo(SendLocationInfo SendLocationInfo) {
		this.SendLocationInfo = SendLocationInfo;
	}

	public SendPicsInfo getSendPicsInfo() {
		return this.SendPicsInfo;
	}

	@XmlElement(name = "SendPicsInfo")
	public void setSendPicsInfo(SendPicsInfo SendPicsInfo) {
		this.SendPicsInfo = SendPicsInfo;
	}

	public TextInputMessage toTextInputMessage() {
		TextInputMessage inputMessage = new TextInputMessage(this.Content);
		this.initNormalMessage(inputMessage);
		return inputMessage;
	}

	public ImageInputMessage toImageInputMessage() {
		ImageInputMessage inputMessage = new ImageInputMessage();
		inputMessage.setPicUrl(this.PicUrl);
		inputMessage.setMediaId(this.MediaId);
		this.initNormalMessage(inputMessage);
		return inputMessage;
	}

	public VoiceInputMessage toVoiceInputMessage() {
		VoiceInputMessage inputMessage = new VoiceInputMessage();
		inputMessage.setFormat(this.PicUrl);
		inputMessage.setMediaId(this.MediaId);
		inputMessage.setRecognition(this.Recognition);
		this.initNormalMessage(inputMessage);
		return inputMessage;
	}

	public VideoInputMessage toVideoInputMessage() {
		VideoInputMessage inputMessage = new VideoInputMessage();
		inputMessage.setMediaId(this.MediaId);
		inputMessage.setThumbMediaId(this.ThumbMediaId);
		this.initNormalMessage(inputMessage);
		return inputMessage;
	}

	public ShortVideoInputMessage toShortVideoInputMessage() {
		ShortVideoInputMessage inputMessage = new ShortVideoInputMessage();
		inputMessage.setMediaId(this.MediaId);
		inputMessage.setThumbMediaId(this.ThumbMediaId);
		this.initNormalMessage(inputMessage);
		return inputMessage;
	}

	public LocationInputMessage toLocationInputMessage() {
		LocationInputMessage inputMessage = new LocationInputMessage();
		inputMessage.setLocation_X(this.Location_X);
		inputMessage.setLocation_Y(this.Location_Y);
		inputMessage.setLabel(this.Label);
		inputMessage.setScale(this.Scale);
		this.initNormalMessage(inputMessage);
		return inputMessage;
	}

	public LinkInputMessage toLinkInputMessage() {
		LinkInputMessage inputMessage = new LinkInputMessage();
		inputMessage.setTitle(this.Title);
		inputMessage.setDescription(this.Description);
		inputMessage.setUrl(this.Url);
		this.initNormalMessage(inputMessage);
		return inputMessage;
	}

	public SubscribeEventMessage toSubscribeEventMessage() {
		SubscribeEventMessage eventMessage = new SubscribeEventMessage();
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public UnSubscribeEventMessage toUnSubscribeEventMessage() {
		UnSubscribeEventMessage eventMessage = new UnSubscribeEventMessage();
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public QrsceneScanEventMessage toQrsceneScanEventMessage() {
		QrsceneScanEventMessage eventMessage = new QrsceneScanEventMessage();
		eventMessage.setEventKey(this.EventKey);
		eventMessage.setTicket(this.Ticket);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public QrsceneSubscribeEventMessage toQrsceneSubscribeEventMessage() {
		QrsceneSubscribeEventMessage eventMessage = new QrsceneSubscribeEventMessage();
		eventMessage.setEventKey(this.EventKey);
		eventMessage.setTicket(this.Ticket);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public LocationEventMessage toLocationEventMessage() {
		LocationEventMessage eventMessage = new LocationEventMessage();
		eventMessage.setLatitude(this.Latitude);
		eventMessage.setLongitude(this.Longitude);
		eventMessage.setPrecision(this.Precision);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public ClickEventMessage toClickEventMessage() {
		ClickEventMessage eventMessage = new ClickEventMessage();
		eventMessage.setEventKey(this.EventKey);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public ViewEventMessage toViewEventMessage() {
		ViewEventMessage eventMessage = new ViewEventMessage();
		eventMessage.setEventKey(this.EventKey);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public ScanCodePushEventMessage toScanCodePushEventMessage() {
		ScanCodePushEventMessage eventMessage = new ScanCodePushEventMessage();
		eventMessage.setEventKey(this.EventKey);
		eventMessage.setScanCodeInfo(this.ScanCodeInfo);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public ScanCodeWaitMsgEventMessage toScanCodeWaitMsgEventMessage() {
		ScanCodeWaitMsgEventMessage eventMessage = new ScanCodeWaitMsgEventMessage();
		eventMessage.setEventKey(this.EventKey);
		eventMessage.setScanCodeInfo(this.ScanCodeInfo);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public PicSysPhotoEventMessage toPicSysPhotoEventMessage() {
		PicSysPhotoEventMessage eventMessage = new PicSysPhotoEventMessage();
		eventMessage.setEventKey(this.EventKey);
		eventMessage.setSendPicsInfo(this.SendPicsInfo);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public PicPhotoOrAlbumEventMessage toPicPhotoOrAlbumEventMessage() {
		PicPhotoOrAlbumEventMessage eventMessage = new PicPhotoOrAlbumEventMessage();
		eventMessage.setEventKey(this.EventKey);
		eventMessage.setSendPicsInfo(this.SendPicsInfo);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public PicWeixinEventMessage toPicWeixinEventMessage() {
		PicWeixinEventMessage eventMessage = new PicWeixinEventMessage();
		eventMessage.setEventKey(this.EventKey);
		eventMessage.setSendPicsInfo(this.SendPicsInfo);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	public LocationSelectEventMessage toLocationSelectEventMessage() {
		LocationSelectEventMessage eventMessage = new LocationSelectEventMessage();
		eventMessage.setEventKey(this.EventKey);
		eventMessage.setSendLocationInfo(this.SendLocationInfo);
		this.initEventMessage(eventMessage);
		return eventMessage;
	}

	private void initNormalMessage(NormalMessage inputMessage) {
		inputMessage.setToUserName(this.getToUserName());
		inputMessage.setFromUserName(this.getFromUserName());
		inputMessage.setMsgId(this.getMsgId());
		inputMessage.setCreateTime(this.getCreateTime());
	}

	private void initEventMessage(EventMessage eventMessage) {
		eventMessage.setToUserName(this.getToUserName());
		eventMessage.setFromUserName(this.getFromUserName());
		eventMessage.setCreateTime(this.getCreateTime());
	}
}
